<template>
	<view>
		<dsl-navbar title="紧急联系人列表" bgTopImg="white" isBack=""></dsl-navbar>

		<view class="padding solid-bottom flex justify-between align-center" v-for="(item,index) in contartList" :key='index' @click="contartMen(item)">
		<view>
			<view>姓名：{{item.name}}</view>
			<view>电话：{{item.mobile}}</view>
			<view>地址：<text class="huanhang text-sm">{{item.address}}</text></view>
		</view>
		<view class="align-center">
			<view class="align-center margin-right" >
				<image style="width: 30rpx;height: 30rpx;" src="/static/img/bianji.png" mode=""></image>
				<view class="fs22 c999 ml20">编辑</view>
			</view>
			<text class="text-red text-sm margin-right" @click.stop="deleteAddress(item)">删除</text>
		<view class="cuIcon-right"></view>
		</view>
		</view>
		
		
		<view>
			<view class="rowjc">
				<view @click="goInfoPage" class="add">添加紧急联系人</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		get_emergencyContactList,
		removeEmergencyContact
	} from '@/common/path.js'
	export default {
		data() {
			return {
				contartList: [],
				isAddress:false,//默认不是从下单页面进入
			}
		},
		//生命周期函数
		onReady() {},
		onLoad(option) {
			if (option.type) {
				this.isAddress = true
				console.log('[选择进入]', true);
			} else {
				this.isAddress = false
				// contart
				uni.removeStorage({  key: 'contart', });
			}
			
		},
		onShow() {
			this.get_emergencyContactList() //紧急联系人
		},
		methods: {
		
		
		//删除紧急联系人
		deleteAddress(item) {
			let self  = this
			uni.showActionSheet({
				itemList: ['删除紧急联系人'],
				success: function(res) {
					if (res.tapIndex == 0) {
						self.deleteAddressApi(item)
					} else {
						
					}
				},
				fail: function(res) {
					console.log(res.errMsg);
				}
			});
		},
		//删除
		deleteAddressApi(item){
			let data = {
				id:item.id
			}
			this.Http.POST(removeEmergencyContact,data)
			.then((res)=>{
				if(res.code ==0){
					this.get_emergencyContactList() //紧急联系人
					this.$tools.showToast2('删除成功')
				}else{
					this.$tools.showToast(res.msg)
				}
			})
		},
		
			//紧急联系人列表
			get_emergencyContactList() {
				let data = {
					userId: uni.getStorageSync('userInfo').id
				}
				this.Http.POST(get_emergencyContactList, data)
					.then((res) => {
						if (res.code == 0) {
							console.log('[联系人]', res);
							this.contartList = res.data
						}
					})
			},
			goInfoPage(){
				uni.navigateTo({
					url:'urgency'
				})
			},
			//跳转下单
			contartMen(item){
				if(this.isAddress){
					uni.setStorageSync('contart',item)
					setTimeout(r=>{
						uni.navigateBack({
							delta:1
						})
					},100)
				}else{
					let data = JSON.stringify(item)
					uni.navigateTo({
						url:'urgency?data=' +data
					})
				}
			}
		},
		computed: {},
		components: {}
	}
</script>

<style>
	.add {
		width: 500rpx;
		height: 80rpx;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 80rpx;
		text-align: center;
		background-color: #29EAC4;
		border-radius: 36rpx;
		position: fixed;
		bottom: 100rpx;
		left: 0;
		right: 0;
		margin: 0 auto;
	
	}
</style>
